package net.siufung.simple.idempotent;

import lombok.AllArgsConstructor;
import net.siufung.boot.redis.service.IRedisClientService;
import net.siufung.web.aop.service.defaults.DefaultAutoIdempotentServiceImpl;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author 陈建峰
 * @date 2022/10/8 6:35 下午
 * @since V1.0.0
 */
@Primary
@Component
@AllArgsConstructor
public class AutoIdempotentServiceImpl extends DefaultAutoIdempotentServiceImpl {

    private final IRedisClientService redisClientService;

    @Override
    public Object getCache(String autoIdempotentKey) {
        return redisClientService.get(autoIdempotentKey);
    }

    @Override
    public void putCache(String idempotentKey, String idempotentValue, long timeout, TimeUnit timeUnit) {
        redisClientService.set(idempotentKey, idempotentValue);
        redisClientService.setExpire(idempotentKey, timeout, timeUnit);
    }
}
